<template>
  <div class="personal-center">
    <div class="title">个人中心</div>
    <div class="user">
      <div class="user-name">
        <div class="name-img">{{ userInfo.userImg }}</div>
        <div>
          <div class="name-top">
            <span class="name">{{ userInfo.userName }}</span>
            <span class="name-type">{{
              userInfo.realName ? '已实名' : '未实名'
            }}</span>
          </div>
          <div class="phone">{{ userInfo.mobile }}</div>
        </div>
      </div>
      <div class="user-setting">
        <div class="cell" @click="router.push('/seal-signing-admin')">
          <svg-icon name="control-stamping" class-name="cell-icon" />
          <div class="cell-content">
            <span class="cell-title">印章签名管理</span
            ><van-icon name="arrow" size="20" color="#CECECE" />
          </div>
        </div>
        <div class="cell">
          <svg-icon name="linkman" class-name="cell-icon" />
          <div class="cell-content">
            <span class="cell-title">常用联系人</span
            ><van-icon name="arrow" size="20" color="#CECECE" />
          </div>
        </div>
        <div class="cell">
          <svg-icon name="rich-scan" class-name="cell-icon" />
          <div class="cell-content">
            <span class="cell-title">扫一扫</span
            ><van-icon name="arrow" size="20" color="#CECECE" />
          </div>
        </div>
        <div class="cell">
          <svg-icon name="customer-service-staff" class-name="cell-icon" />
          <div class="cell-content">
            <span class="cell-title">在线客服</span
            ><van-icon name="arrow" size="20" color="#CECECE" />
          </div>
        </div>
      </div>
      <van-button class="exit-btn" block type="default" @click="exitClick"
        >退出登录</van-button
      >
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from '@/store'
import { Dialog } from 'vant'
import { getDetectionFaceSwiping } from '@/api/face-swiping'
import { clearItem } from '@/utils/storage'
export default defineComponent({
  setup() {
    const router = useRouter()
    const store = useStore()
    const userInfo = reactive({
      userName: store.state.login.userInfo.userName,
      userImg: store.state.login.userInfo.userName.split('')[0],
      mobile: store.state.login.userInfo.mobile,
      realName: 1
    })

    // 实名检测
    const changeDetectionFaceSwiping = async () => {
      const res = await getDetectionFaceSwiping({
        idNumber: store.state.login.userInfo.idNumber
      })
      if (res.code !== '0') {
        userInfo.realName = 0
      } else {
        userInfo.realName = 1
      }
    }
    changeDetectionFaceSwiping()
    // 退出登录
    const exitClick = () => {
      Dialog.confirm({
        title: '确定要退出当前登录吗?'
      })
        .then(() => {
          clearItem()
          router.push('/login')
        })
        .catch(() => {
          // on cancel
        })
    }
    return { userInfo, exitClick, router }
  }
})
</script>

<style scoped lang="less">
.personal-center {
  height: 100%;
  width: 100%;
  .title {
    height: 46px;
    background-color: #fff;
    text-align: center;
    line-height: 46px;
    font-size: 17px;
    font-weight: 700;
  }
  .user {
    padding: 12px 20px;
    .user-name {
      height: 100px;
      background-color: #fff;
      display: flex;
      align-items: center;
      padding: 0 20px;
      border-radius: 4px;
      .name-img {
        height: 54px;
        width: 54px;
        margin-right: 15px;
        border-radius: 50%;
        background-color: #2489f2;
        line-height: 54px;
        text-align: center;
        font-size: 19px;
        color: #fff;
      }
      .name-top {
        display: flex;
        align-items: center;
        padding-bottom: 8px;
        .name {
          font-size: 17px;
          font-weight: 700;
          color: #101010;
        }
        .name-type {
          display: inline-block;
          padding: 3px 4px;
          margin-left: 16px;
          border: 1px solid #18c388;
          border-radius: 4px;
          font-size: 12px;
          color: #18c388;
        }
      }

      .phone {
        font-size: 14px;
        color: #999;
      }
    }
    .user-setting {
      margin-top: 12px;
      background-color: #fff;
      border-radius: 4px;
      .cell {
        height: 60px;
        display: flex;
        align-items: center;
        padding: 0 16px;
        .cell-icon {
          width: 22px;
          height: 22px;
          margin-right: 16px;
        }
        .cell-content {
          display: flex;
          justify-content: space-between;
          align-items: center;
          height: 100%;
          width: 100%;
          border-bottom: 1px solid #e4e4e4;

          .cell-title {
            font-size: 15px;
            font-weight: 600;
            color: #101010;
          }
        }
      }
      .cell:last-child .cell-content {
        border-bottom: none;
      }
      .cell:active {
        background-color: #f2f3f5;
      }
    }
    .exit-btn {
      height: 54px;
      border: none;
      margin-top: 12px;
      border-radius: 4px;
      font-size: 15px;
      color: #999;
    }
  }
}
</style>
